package com.chinamsp.dydb.query;

import org.springframework.util.Assert;

import com.chinamsp.dydb.crud.QueryOrderType;

/**
 * 排序实体
 * @author shifenghu
 *
 */
public class OrderBy {
	
	/**
	 * 排序字段
	 */
	private String orderField;
	
	/**
	 * 排序类型
	 */
	private QueryOrderType orderType;
	
	
	public OrderBy() {}
	
	public OrderBy(String orderField, QueryOrderType orderType) {
		this.orderField = orderField;
		this.orderType = orderType;
	}
	

	public String getOrderField() {
		return orderField;
	}

	public void setOrderField(String orderField) {
		this.orderField = orderField;
	}

	public QueryOrderType getOrderType() {
		return orderType;
	}

	public void setOrderType(QueryOrderType orderType) {
		this.orderType = orderType;
	}
	
	
	/**
	 * 初始化一个排序对象
	 * @param field
	 * @param orderType
	 * @return
	 */
	public static OrderBy newOrder(String field, QueryOrderType orderType){
		Assert.notNull(orderType, "排序类型必须存在");
		Assert.notNull(field, "排序字段必须存在");
		OrderBy order = new OrderBy();
		order.setOrderField(field);
		order.setOrderType(orderType);
		return order;
	}
}
